<?php
// +---------------------------------------------------------------------+
// | OneBase    | [ WE CAN DO IT JUST THINK ]                            |
// +---------------------------------------------------------------------+
// | Licensed   | http://www.apache.org/licenses/LICENSE-2.0 )           |
// +---------------------------------------------------------------------+
// | Author     | Bigotry <3162875@qq.com>                               |
// +---------------------------------------------------------------------+
// | Repository | https://gitee.com/Bigotry/OneBase                      |
// +---------------------------------------------------------------------+

namespace app\admin\logic;

/**
 * 挂机方案逻辑
 */
class Plan extends AdminBase
{
    
  
    
    /**
     * 获取挂机方案列表
     */
    public function getPlanList($where = [], $field = 'a.*', $order = '')
    {
        
        $this->modelThirdPlan->alias('a');
        
       
        $where['a.' . DATA_STATUS_NAME] = ['neq', DATA_DELETE];
        $list=$this->modelThirdPlan->getList($where, $field, $order);
        $this->modelThirdPlan->alias('a');
        $count=$this->modelThirdPlan->where($where)->count();
        return ['list'=>$list,'count'=>$count];
    }


    /**
     * 获取挂机方案列表
     */
    public function getPlanBetList($data, $field = 'a.*', $order = '')
    {

        $this->modelPlanNumber->alias('a');


        $where['a.' . DATA_STATUS_NAME] = ['neq', DATA_DELETE];
        $where['a.plan_id']=$data['id'];

        if (!empty($data['date1']) && !empty($data['date2']) ) {
            $where['a.create_time'] = ['between', [strtotime($data['date1'] . ' 00:00:00'), strtotime($data['date2'] . ' 23:59:59')]];
        }
        !empty($data['lottery_id']) && $where['a.lottery_id']=$data['lottery_id'];
        !empty($data['play_id']) && $where['a.play_id']=$data['play_id'];
        $list=$this->modelPlanNumber->getList($where, $field, $order);
        $this->modelPlanNumber->alias('a');
        $count=$this->modelPlanNumber->where($where)->count();
        return ['list'=>$list,'count'=>$count];
    }
    
    /**
     * 获取挂机方案列表搜索条件
     */
    public function getWhere($data = [])
    {
        
        $where = [];
        
        !empty($data['search_data']) && $where['a.title'] = ['like', '%'.$data['search_data'].'%'];
        return $where;
    }
    
    /**
     * 挂机方案信息编辑
     */
    public function PlanEdit($data = [])
    {



        $url = url('PlanList');
        $max_bureaus=0;


        $result = $this->modelThirdPlan->setInfo($data);
        
        $handle_text = empty($data['id']) ? '新增' : '编辑';
        
        $result && action_log($handle_text, '方案' . $handle_text . '，方案名称：' . $data['title']);
        
        return $result ? [RESULT_SUCCESS, '方案操作成功', $url] : [RESULT_ERROR, $this->modelThirdPlan->getError()];
    }

    /**
     * 获取挂机方案信息
     */
    public function getPlanInfo($where = [], $field = 'a.*')
    {
        
        $this->modelThirdPlan->alias('a');


        
        $where['a.' . DATA_STATUS_NAME] = ['neq', DATA_DELETE];
        

        
        return $this->modelThirdPlan->getInfo($where, $field);
    }


    /**
     * 挂机方案删除
     */
    public function update_info($where = [])
    {

        //dd($where);

        $result = $this->modelThirdPlan->setInfo($where);


        return $result ? [RESULT_SUCCESS, '操作成功'] : [RESULT_ERROR, '操作失败'];
    }


}
